﻿using System;
using CustomerAssistant.Core;

namespace CustomerAssistantWebServer
{
    public class Global : System.Web.HttpApplication
    {
        protected void Application_Start(object sender, EventArgs e)
        {
            var assemblies = AppDomain.CurrentDomain.GetAssemblies();
            //开始动态创建请求职责链
            IClientHandle _handle = null, _header = null;
            foreach (var assembly in assemblies)
            {
                var types = assembly.GetTypes();
                foreach (Type type in types)
                {
                    if (type.GetInterface("IClientHandle") != null)
                    {
                        var instance = (IClientHandle)assembly.CreateInstance(type.FullName);
                        if (_handle == null)
                            _header = _handle = instance;
                        else
                            _handle = _handle.NextNode = instance;
                    }
                }
            }
            Application.Add(Util.CLIENTHANDLECHAIN_KEY, _header);
        }

        protected void Session_Start(object sender, EventArgs e)
        {
        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {
        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {
        }

        protected void Application_Error(object sender, EventArgs e)
        {
        }

        protected void Session_End(object sender, EventArgs e)
        {
        }

        protected void Application_End(object sender, EventArgs e)
        {
        }
    }
}